package com.ibm.sc.osp.sample.service.impl;

import com.ibm.sc.osp.sample.domain.entity.Message;
import com.ibm.sc.osp.sample.repository.MessageRepository;
import com.ibm.sc.osp.sample.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service("MessageService")
//service具体实现类
public class MessageServiceImpl implements MessageService {
    
    @Autowired
    private MessageRepository messageRepository;
    
    @Override
    public Message add(Message message) {
        return messageRepository.saveAndFlush(message);
    }
    
    @Override
    public String remove(String id) {
        Message message = messageRepository.findOne(id);
        message.setDelFlag(Message.DEL_FLAG_DELETE);
        messageRepository.saveAndFlush(message);
        return id;
    }
    
    @Override
    public Message update(Message message) {
        Message message_db = messageRepository.findOne(message.getId());
        return messageRepository.saveAndFlush(message_db);
    }
    
    @Override
    public Message get(String id) {
        return messageRepository.findOne(id);
    }
    
    @Override
    public Page<Message> findAll(PageRequest page) {
        return messageRepository.findAll(page);
    }
    
}
